package com.ruoyi.operation.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.operation.domain.*;
import com.ruoyi.operation.mapper.TradeingActivityMapper;
import com.ruoyi.operation.service.TradeingActivityService;
import com.ruoyi.util.OkHttpUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.List;

@Service
public class TradeingActivityServiceImpl implements TradeingActivityService {

    @Autowired
    TradeingActivityMapper tradeingActivityMapper;

    @Override
    public List<TradingActivity> getTradeingActivityType(String type, RequestBO requestBO) {
        if ("MONTH".equals(type)) {
            return tradeingActivityMapper.getTradeingActivityTypeByMonth(requestBO);
        }
        if ("HOUR".equals(type)) {
            return tradeingActivityMapper.getTradeingActivityTypeByHour(requestBO);
        }


        return null;
    }

    @Override
    public List<PayWayWIthNum> getPayWayNum(RequestBO requestBO) {
        return tradeingActivityMapper.getPayWayNum(requestBO);
    }

    @Override
    public List<MonthPrice> getMonthPrice(String type, RequestBO requestBO) {

        if ("CONSUMER".equals(type)) {
            return tradeingActivityMapper.getMonthConsumerPriceList(requestBO);
        }
        if ("REPAYMENT".equals(type)) {
            return tradeingActivityMapper.getMonthepayRepaymentPriceList(requestBO);

        }
        return null;
    }

    @Override
    public List<MechanismUseNum> getMechanismUseNumList(RequestBO requestBO) {
        return tradeingActivityMapper.getMechanismUseNumList(requestBO);
    }

    @Override
    public List<PlatformStatus> getPlatformStatusList(RequestBO requestBO) {
        return tradeingActivityMapper.getPlatformStatusList(requestBO);
    }

    @Override
    public List<MonthApply> getMonthApplyList(RequestBO requestBO) {
        return tradeingActivityMapper.getMonthApplyList(requestBO);
    }

    @Override
    public List<MonthApply> getMonthRefuseList(RequestBO requestBO) {
        return tradeingActivityMapper.getMonthRefuseList(requestBO);
    }

    @Override
    public List<PlatformSumCount> getPlatformSumCountList(RequestBO requestBO) {
        return tradeingActivityMapper.getPlatformSumCountList(requestBO);
    }

    @Override
    public List<PlatformStatus> getLoanStautsList(RequestBO requestBO) {
        return tradeingActivityMapper.getLoanStautsList(requestBO);
    }

    @Override
    public List<PlatformStatus> getRepayStautsList(RequestBO requestBO) {
        return tradeingActivityMapper.getRepayStautsList(requestBO);
    }

    @Override
    public List<PlatformSumCount> getRepayPlatformSumList(RequestBO requestBO) {
        return tradeingActivityMapper.getRepayPlatformSumList(requestBO);
    }

    @Override
    public List<MonthNumApply> getRepayPlatformMonthNumSumList(RequestBO requestBO) {
        return tradeingActivityMapper.getRepayPlatformMonthNumSumList(requestBO);
    }

    @Override
    public List<UserInfo> getUserInfoList(RequestBO requestBO) {
        return tradeingActivityMapper.getUserInfoList(requestBO);
    }

    @Override
    public List<TotalOutPut> getTotalOutputList(RequestBO requestBO) {
        return tradeingActivityMapper.getTotalOutputList(requestBO);
    }

    @Override
    public List<MonthInOut> getMonthInOutList(RequestBO requestBO) {
        return tradeingActivityMapper.getMonthInOutList(requestBO);
    }

    @Override
    public String invokeDify(String query) throws IOException {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("data_query","今天星期几");
        String sync = OkHttpUtils.builder().url("https://api.dify.ai/v1/workflows/run")
                .addHeader("Authorization", "Bearer app-hqV7Qr0UUryLVPdukiX03VUC")
                .addParam("response_mode", "blocking")
                .addParam("user", "rua")
                .addParam("inputs", JSON.toJSONString(jsonObject))
                .post(true) // true 为json提交方式
                .sync();
        System.out.println(sync);


        return null;
    }
}
